<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Hugo 0.83.1">
    <title>用户管理</title>
    <!-- Bootstrap core CSS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js"></script>
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }
    </style>
    <!-- Custom styles for this template -->
    <link href="/css/dashboard.css" rel="stylesheet">
</head>
<body>

<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
    <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">用户管理</a>
    <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse"
            data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false"
            aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <!--    <input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">-->
    <ul class="navbar-nav px-3">
        <li class="nav-item text-nowrap">
            <a class="nav-link" href="/logout">注销</a>
        </li>
    </ul>
</header>

<div class="container-fluid">
    <div class="row">
        <nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
            <div class="position-sticky pt-3">
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link " aria-current="page" href="/main">
                            <span data-feather="home"></span>
                            项目总览
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link " href="/search">
                            <span data-feather="search"></span>
                            项目搜索
                        </a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link active" href="/user">
                            <span data-feather="users"></span>
                            用户管理
                        </a>
                    </li>
                </ul>

                <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
                    <span>项目调整</span>
                </h6>
                <ul class="nav flex-column mb-2">
                    <li class="nav-item">
                        <a class="nav-link" href="/add">
                            <span data-feather="file-plus"></span>
                            增加项目
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/edit">
                            <span data-feather="edit"></span>
                            修改项目
                        </a>
                    </li>
<!--                    <li class="nav-item">-->
<!--                        <a class="nav-link" href="/delete.html">-->
<!--                            <span data-feather="trash-2"></span>-->
<!--                            删除项目-->
<!--                        </a>-->
<!--                    </li>-->
                </ul>
            </div>
        </nav>

        <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
            <h2>用户管理</h2>
            <div class="table-responsive">
                <table class="table table-striped table-sm" id="table" data-toggle="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>用户名</th>
                        <th>密码</th>
                        <th>修改</th>
                        <th>删除</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="user,status:${users}">
                        <td  th:text="${status.count}">序号</td>
                        <td th:id="name+${status.count}" th:text="${user.getUsername()}">后端传值</td>
                        <td th:id="pwd+${status.count}" th:text="${user.getPassword()}">后端传值</td>
                        <td>
<!--                            <button type="button" class="btn btn-outline-info btn-sm" >修改</button>-->
                            <button th:id="edit+${status.count}" type="button" class="btn btn-outline-info btn-sm"
                                   onclick="autoinfo(this.id)" data-bs-toggle="modal" data-bs-target="#exampleModal">修改</button>

                        </td>
                        <td>
                            <button th:id="delete+${status.count}" type="button" class="btn btn-outline-danger btn-sm" onclick="dodelete(this.id)">删除</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <!-- 修改用户信息Modal弹出窗口 -->
            <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">用户信息修改</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <form action="/edituser">

                                <div class="input-group mb-3">
                                    <span class="input-group-text" id="basic-addon">用户账号</span>
                                    <input id="in1" name="username" type="text" class="form-control" placeholder="用户名建议为英文"
                                           aria-label="Username" aria-describedby="basic-addon1">
                                </div>
                                <div class="input-group mb-3">
                                    <span class="input-group-text" id="basic-addon1">用户密码</span>
                                    <input id="in2" name="password" type="text" class="form-control" placeholder="密码建议大于四位"
                                           aria-label="Username" aria-describedby="basic-addon1">
                                </div>
                                <button id="formbottom" type="submit" class="btn btn-primary" style="display: none">提交</button>
                            </form>

                        </div>
                        <div class="modal-footer">
                            <button type="button" id="close" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                            <button type="button" onclick="dosubmit()" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </div>
            </div>



            <button id="adduser" type="button" class="btn btn-outline-success btn-sm"
                     data-bs-toggle="modal" data-bs-target="#addModal">添加用户</button>
            <!-- 添加用户信息窗口         -->
            <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="addModalLabel">添加用户信息</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <form action="/adduser">

                                <div class="input-group mb-3">
                                    <span class="input-group-text" id="add-basic-addon">用户账号</span>
                                    <input id="ad1" name="username" type="text" class="form-control" placeholder="用户名建议为英文"
                                           aria-label="Username" aria-describedby="basic-addon1">
                                </div>
                                <div class="input-group mb-3">
                                    <span class="input-group-text" id="addbasic-addon1">用户密码</span>
                                    <input id="ad2" name="password" type="text" class="form-control" placeholder="密码建议大于四位"
                                           aria-label="Username" aria-describedby="basic-addon1">
                                </div>
                                <button id="addbottom" type="submit" class="btn btn-primary" style="display: none">提交</button>
                            </form>

                        </div>
                        <div class="modal-footer">
                            <button type="button" id="close2" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                            <button type="button" onclick="doadd()" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </div>
            </div>

        </main>

    </div>
</div>

<!--            弹窗-->
<div id="simpleModal" class="modal">
    <div class="modal-content">
        <div class="modal-header">
            <span class="closeBtn">&times;</span>
            <h2>弹框头部</h2>
        </div>
        <div class="modal-body">
            <p>这是一个弹窗效果</p>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis, nemo? Temporibus velit
                eligendi neque repudiandae quis, autem vero fuga officia enim quas quibusdam consequuntur
                nam dolores tempore asperiores repellendus distinctio.</p>
        </div>
        <div class="modal-footer">
            <h3>弹框底部</h3>
        </div>
    </div>
</div>


<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"
        integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE"
        crossorigin="anonymous"></script>
<script>
    /* globals Chart:false, feather:false */
    (function () {
        feather.replace()
    })();

    function dosubmit(){
        $("#formbottom").click();
        $("#close").click();
    }
    function doadd(){
        $("#addbottom").click();
        $("#close2").click();
    }

    function autoinfo(id){
        id = id.substring(4,id.length)
        const name = "name" + id;
        const pwd = "pwd"+id;
        const username = $("#"+name+"").text()
        const password = $("#"+pwd+"").text()
        $("#in1").val(username)
        $("#in2").val(password)
    }

    function re(){
        location.reload()
    }

    function dodelete(id){
        const  result=window.confirm("你确定要删除吗");
        if (result==false){
            return;
        }
        id = id.substring(6,id.length)
        const name = "name" + id;
        const pwd = "pwd"+id;
        const username = $("#"+name+"").text()
        const password = $("#"+pwd+"").text()
        // console.log(username+" "+password)
        const host = window.location.host;
        uurl = "http://"+host+"/deleteuser?username="+username+"&password="+password;
        // console.log(uurl)
        $.ajax({
            url: uurl,
            type: "GET"
        })
        setTimeout(re,1000)
    }
</script>
</body>
</html>
